<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class Site_config_model  extends MY_Model  {

    public $table = 'site_config';
    public $id = '';
	public $config_key = '';
	public $last_updated = '';
	public $config_value = '';

	public function __construct() {
		$this->class_name = get_class ( $this );
		parent::__construct( $this->class_name, $this->table );
		parent::init( $this->class_name, $this->table );
	}
		
	public function getByKey($key){
		$result =  $this->db->select()->from($this->table)->where('config_key',$key)->get()->row();
    	$obj = FALSE;
    	if ($result){
    		$obj = new Site_config_model();
            $obj->id = $result->id;
    		$obj->last_updated = $result->last_updated;
    		$obj->config_value = $result->config_value;
			$obj->config_key = $result->config_key;
    	}
    	return $obj;
	}
	
	public function update(){
		$data = array(
    		'last_updated'=>date('Y-m-d H:i:s'),
	    	'config_value'=>$this->config_value
		);
		$this->db->where('config_key',$this->config_key);
		$this->db->update($this->table,$data);
	}
	
	public function insert(){
    	$data = array(
    		'config_key'=>$this->config_key,
    		'last_updated'=>date('Y-m-d H:i:s'),
	    	'config_value'=>$this->config_value
    	);
    	$this->db->insert($this->table,$data);
    }
}